package com.tencet.servlet;

import com.tencet.entity.AccountOne;
import com.tencet.service.Impl.AccountOneServiceImpl;
import com.tencet.service.Impl.TransferServiceImpl;
import com.tencet.service.TransferService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author: @date: 2022/7/21 22:09
 * @description:
 */
@WebServlet("/transfer")
public class TransferServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        TransferService transferService = new TransferServiceImpl();
        String reduce_num = req.getParameter("reduce_num");
        String add_num = req.getParameter("add_num");
        int money = Integer.parseInt(req.getParameter("money"));

        List<AccountOne> accountList = (List<AccountOne>) req.getSession().getAttribute("accountList");
        String accountId1del = "";
        String accountId2add = "";
        for (int i = 0; i < accountList.size(); i++) {
            if (accountList.get(i).getCard_num().equals(reduce_num)){
                accountId1del = accountList.get(i).getAccount_id1();
            }
            if (accountList.get(i).getCard_num().equals(add_num)) {
                accountId2add = accountList.get(i).getAccount_id1();
            }
//            AccountOne accountOne = accountList.get(i);
//            String card_num = accountOne.getCard_num();
//            if (card_num.equals(reduce_num)){
//                accountId1del = accountOne.getAccount_id1();
//            }
        }

        System.out.println("所有银行卡id");
        System.out.println(accountList);

        System.out.println("accountId2add = " + accountId2add);
        System.out.println("accountId1del = " + accountId1del);
        boolean b = transferService.transfer(money,accountId2add,accountId1del);
        resp.getWriter().write(""+b);
    }
}